<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Jobs\GetPictuerAverageJobs;
use App\Models\Pictuer;
class GetPictuerAverage extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'tx:get-pictuer-average {nums=0}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '从 OSS 获取图片的 主色调';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(Pictuer $pictuer)
    {
        $this->info('获取图片色调');
        $nums = $this->argument('nums');
        if (!$nums) $nums = 100;
        // 获取图片
        $pictuers = Pictuer::where('rgb', null)->limit($nums)->get()->toArray();
        if (count($pictuers) > 0) {
          dispatch(new GetPictuerAverageJobs($pictuers));
        }
        $this->info('完成操作');
    }
}
